package com.example.sls.service.impl.teacher.publish;

import com.example.sls.pojo.teacher.proSet.ProSet;
import com.example.sls.pojo.teacher.publish.Publish;
import com.example.sls.mapper.teacher.publish.PublishMapper;
import com.example.sls.service.teacher.publish.PublishService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PublishServiceImpl implements PublishService {
    @Autowired
    private PublishMapper publishMapper;

    @Override
    public Boolean publishSet(Publish publish) {
        boolean flag = false;
        if(publishMapper.publishSet(publish) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public Boolean deleteSet(Integer setId, Integer classId) {
        boolean flag = false;
        //System.out.println("impl-deleteSet: " + publishMapper.deleteSet(setId, classId));
        if(publishMapper.deleteSet(setId, classId) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public PageInfo<Publish> getPublishInfoByCId(Integer classId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Publish> infos = publishMapper.getPublishInfoByCId(classId);
        return new PageInfo<Publish>(infos);
    }

    @Override
    public List<ProSet> getUnpublishedProset(Integer teacherId, Integer classId) {
        return publishMapper.getUnpublishedProset(teacherId, classId);
    }

    @Override
    public List<Integer> getUnpublishedSetId(Integer teacherId, Integer classId) {
        return publishMapper.getUnpublishedSetId(teacherId, classId);
    }


    @Override
    public PageInfo<Publish> getPublishInfo(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Publish> infos = publishMapper.getPublishInfo();
        return new PageInfo<Publish>(infos);
    }

    @Override
    public Integer getMaxId() {
        return publishMapper.getMaxId();
    }

    @Override
    public Integer getCount() {
        return publishMapper.getCount();
    }
}
